package com.st.event.demo.source.impl;

import com.st.event.demo.source.AbstractEventAttributeSource;
import com.st.event.demo.source.EventAnnotationSourceParser;
import com.st.event.demo.source.EventAttribute;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

public class DefaultEventAttributeSource extends AbstractEventAttributeSource {

    private List<EventAnnotationSourceParser> parsers = new ArrayList<>();

    public DefaultEventAttributeSource(List<EventAnnotationSourceParser> parsers) {
        System.out.println("执行12-----------");
        if (parsers == null || parsers.isEmpty()) {
            this.parsers.add(new DefaultEventAnnotationSourceParser());
        }
        this.parsers = parsers;
    }

    @Override
    protected EventAttribute findEventAttribute(Method method) {
        System.out.println("执行13-----------");
        for (EventAnnotationSourceParser parser : parsers) {
            EventAttribute attr = parser.parsePayAnnotation(method);
            if (attr != null) {
                return attr;
            }
        }
        return null;
    }
}
